﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;

namespace EnCor.CallingTrack
{
    public class CallingContext
    {
        
        private Stack<ServiceCallInfo> _Stack = new Stack<ServiceCallInfo>();

        [ThreadStatic]
        private static CallingContext _Current = new CallingContext();

        public static CallingContext Current
        {
            get
            {
                if (_Current == null)
                {
                    _Current = new CallingContext();
                }
                return _Current;
            }
        }

        internal ServiceCallInfo Push(BizService bizService, MethodBase method)
        {
            ServiceCallInfo callInfo = new ServiceCallInfo(bizService, method);
            _Stack.Push(callInfo);
            return callInfo;
        }

        internal ServiceCallInfo Pop()
        {
            return _Stack.Pop();
        }

        internal ServiceCallInfo Peek()
        {
            return _Stack.Peek();
        }


    }
}
